package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqoptrade.resp.Order;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.ConfirmReceiveNotifyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.shenqi.SqTradingCallService;

/**
 * 自动确认收货提醒通知FreeMaker Template自动生成代码
 */
@TestSuite
@Ignore
public class Ts_AutoConfirmReceiveNotify {

	private static ConfirmReceiveNotifyCall confirmReceiveNotifyCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买家确认收货");
	}

	@Before
	public void caseUp() {

		confirmReceiveNotifyCall = new ConfirmReceiveNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(confirmReceiveNotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AutoConfirmReceiveNotify_001() {
		Logger.start(true, "订单下所有面单都已签收");
		try {

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder3(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			//发货
			SqTradingCallService.delivery(orderId);

			String billNo1 = "DB11320536300";

			// 码头保存物流单号
			SqTradingCallService.saveDeliverSummary(orderId, sellerId, billNo1);

			// 发送请求
			confirmReceiveNotifyCall.setData("{}");
			confirmReceiveNotifyCall.callService();
			Logger.verifyEquals("ok", confirmReceiveNotifyCall.getReturnData(),
					"验证接口返回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	// notify_order_to_be_auto_confirm_received 发通知 消息
	public void Tc_AutoConfirmReceiveNotify_002() {
		Logger.start(false, "订单下所有面单有未签收");
		try {
			

			// 发送请求
			confirmReceiveNotifyCall.setData("{}");
			confirmReceiveNotifyCall.callService();
			Logger.verifyEquals("ok", confirmReceiveNotifyCall.getReturnData(),
					"验证接口返回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}
